﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace UI.Forms
{
    public partial class empMgr : FormBase1
    {
        public empMgr()
        {
            InitializeComponent();
        }

        private void btn_new_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Emp_N frm = new Emp_N();
            frm.FatherRefresh = bind;
            frm.ShowDialog();
        }

        private void empMgr_Load(object sender, EventArgs e)
        {
            bind();
            rlue_shop.DataSource = my.bw.shop_Get("", my.ACID);
            rlue_shop.DisplayMember = "name";
            rlue_shop.ValueMember = "shopcode";
        }

        private void bind()
        {
            gridControl1.DataSource = my.bw.Employee_Get("", my.ACID);
        }

        private void btn_sx_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            bind();
        }

        private void btn_delete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (gridView1.FocusedRowHandle>=0)
            {
                SVC.client.Employee emp = gridView1.GetRow(gridView1.FocusedRowHandle) as SVC.client.Employee;
                if (emp!=null)
                {
                    if (DialogResult.OK != XtraMessageBox.Show("删除后不可恢复，确定要删除？", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button2)) return;
                    string r = my.bw.EmployeeByEmplID_Delete(emp.EmplID, my.ACID);
                    if (!string.IsNullOrEmpty(r))
                    {
                        Comm.ShowErorr(r);
                    }
                    else
                    {
                        bind();
                    }
                }
            }
        }

        private void btn_update_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (gridView1.FocusedRowHandle >= 0)
            {
                SVC.client.Employee emp = gridView1.GetRow(gridView1.FocusedRowHandle) as SVC.client.Employee;
                if (emp != null)
                {
                    Emp_U frm = new Emp_U(emp);
                    frm.FatherRefresh = bind;
                    frm.ShowDialog();
                }
            }
        }

        private void btn_mm_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (gridView1.FocusedRowHandle >= 0)
            {
                SVC.client.Employee emp = gridView1.GetRow(gridView1.FocusedRowHandle) as SVC.client.Employee;
                if (emp != null)
                {
                    Emp_U frm = new Emp_U(emp);
                    frm.FatherRefresh = bind;
                    frm.ShowDialog();
                }
            }
        }
    }
}